package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.VideoBean;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/12/22.
 */
public class VideoAdapter extends BaseAdapter {
    private Context context;

    private List<VideoBean> videoBean=new ArrayList<>();

    public VideoAdapter(Context context,
                        List<VideoBean> videoBean) {
        this.videoBean = videoBean;
        this.context = context;

    }

    @Override
    public int getCount() {
        return videoBean.size();
    }

    @Override
    public Object getItem(int position) {
        return videoBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VideoViewHolder viewHolder = new VideoViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.video_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (VideoViewHolder) convertView.getTag();
        }
        x.image().bind(viewHolder.iv_img,videoBean.get(position).getImg());
        viewHolder.tv_time.setText(videoBean.get(position).getTitle());

        return convertView;
    }

    class VideoViewHolder {
        ImageView iv_img;
        TextView tv_title;
        TextView tv_time;
    }
}
